import { createI18n } from 'vue-i18n';
//导入语言文件 

import AppVue from '@/App.vue';
import { LanguageEnum } from '@/enums/appEnum';
import { useSidebarStore } from '@/store/sidebar';
import { createPinia } from 'pinia';
import { App, createApp } from 'vue';

const pinia = createPinia()
const app = createApp(AppVue)

app.use(pinia)

const localeStore = useSidebarStore()

const localeType = localeStore.localeInfo

export let messages:any = {}

for (const key in LanguageEnum) {
  const localePkg = await import(`./locales/${key}.ts`)
  messages[key] = localePkg.default
}

//i18n实例配置
const localeData = {
  globalInjection: true, //如果设置true, $t() 函数将注册到全局
  legacy: false, //如果想在composition api中使用需要设置为false
  // set locale
  // options: en | zh | es
  locale: localeType,
  messages  // set locale messages
}


// 提供install方法，给vue.use进行创建实例
export async function setupI18n(app: App) {
  const i18n = createI18n(localeData)
  app.use(i18n)
}

export default createI18n(localeData)